package com.x.chalk.controller;
////////////////////////////////////////////////////////////////////
//                          _ooOoo_                               //
//                         o8888888o                              //
//                         88" . "88                              //
//                         (| ^_^ |)                              //
//                         O\  =  /O                              //
//                      ____/`---'\____                           //
//                    .'  \\|     |//  `.                         //
//                   /  \\|||  :  |||//  \                        //
//                  /  _||||| -:- |||||-  \                       //
//                  |   | \\\  -  /// |   |                       //
//                  | \_|  ''\---/''  |   |                       //
//                  \  .-\__  `-`  ___/-. /                       //
//                ___`. .'  /--.--\  `. . ___                     //
//              ."" '<  `.___\_<|>_/___.'  >'"".                  //
//            | | :  `- \`.;`\ _ /`;.`/ - ` : | |                 //
//            \  \ `-.   \_ __\ /__ _/   .-` /  /                 //
//      ========`-.____`-.___\_____/___.-`____.-'========         //
//                           `=---='                              //
//      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^        //
//            佛祖保佑       永不宕机     永无BUG                   //
////////////////////////////////////////////////////////////////////

import com.x.chalk.config.SystemConfig;
import com.x.chalk.entity.Address;
import com.x.chalk.service.intf.AddressService;
import com.x.chalk.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author wsc
 * @create 2022-10-05 14:14
 */
@RestController
@RequestMapping("/api/address/")
@CrossOrigin
@Api(tags = "收货地址相关操作")
public class AddressController {

    @Resource
    private AddressService service;

    @PostMapping("add.do")
    @ApiOperation(value = "添加收货地址")
    public R add(@RequestBody Address address, HttpServletRequest request){
        return service.add(address,request.getHeader(SystemConfig.HEADER_TOKEN));
    }

    @GetMapping("del.do")
    @ApiOperation(value = "删除收货地址")
    public R del( @ApiParam(value = "收货地址id") long id){
        return service.del(id);
    }

    @GetMapping("my.do")
    @ApiOperation(value = "查询我的收货地址")
    public R queryMy(HttpServletRequest request){
        return service.queryMy(request.getHeader(SystemConfig.HEADER_TOKEN));
    }

    @GetMapping("detail.do")
    @ApiOperation(value = "查询收货地址详情")
    public R detail( @ApiParam(value = "收货地址id") long id){
        return service.selectById(id);
    }

    @PostMapping("update.do")
    @ApiOperation(value = "修改收货地址")
    public R update(@RequestBody Address address){
        return service.update(address);
    }

}
